-----------------------------------------------------------------------------------------
-- filename : pause_scene.lua
-- description : pause scene. All logic for pause in here
-----------------------------------------------------------------------------------------

-- Load needed libraries/scripts
local storyboard = require "storyboard"
local fontfactory = require "fontfactory"
local scene = storyboard.newScene()
local callback = nil
local storyboard = require "storyboard"
local button = require "button"

function scene:createScene(event)
	print("Pause Scene")
	callback = event.params.callback
	self._playerid = event.params.playerid
	local img_char = event.params.character
	local group = self.view

	local back = display.newRect( group, 0, 0, display.actualContentWidth,display.actualContentHeight )
	back:setFillColor(0, 0, 0, 1.0)
	back:addEventListener("touch", castRay)
	back:addEventListener("tap", castRay)

	local bg = display.newImageRect( group,"assets/pause/base_pause.png", 382, 313 )
	local player_text = display.newText(group,"Player "..(self._playerid+1), 212 + display.screenOriginX, 100, fontfactory.dimitry, 20)
	local pause_text = display.newText(group,"Pause Menu", 212 + display.screenOriginX, 118, fontfactory.dimitry, 20)
	local image_char = nil
	if(img_char ~= nil) then
		image_char = display.newImageRect( group,img_char, 200, 200 )
		image_char.x = 95 + display.screenOriginX
		image_char.y = 155
		image_char.xScale = 0.8
		image_char.yScale = 0.8
	end

	player_text:setTextColor(207, 223, 222)
	pause_text:setTextColor(207, 223, 222)
	bg:setReferencePoint(display.TopLeftReferencePoint)

	if(self._playerid == 0) then -- pause scene for left player
		bg.y = 30
		bg.x = -20 + display.screenOriginX
		button.createButtonAlphaAnim(self,"RESUME",200 + display.screenOriginX,150,resume,0.7)
		button.createButtonAlphaAnim(self,"QUIT",200 + display.screenOriginX,180,nil,0.7)
		button.createButtonAlphaAnim(self,"HELP",200 + display.screenOriginX,210,nil,0.7)
		button.createButtonAlphaAnim(self,"MAIN MENU",200 + display.screenOriginX,240,nil,0.7)
	else -- pause scene for right player
		bg.xScale = -1
		bg.y = 30
		bg.x = 500 - display.screenOriginX
		player_text.x = 225 - display.screenOriginX
		pause_text.x = 213 - display.screenOriginX
		button.createButtonAlphaAnim(self,"RESUME",149 - display.screenOriginX,150,resume,0.7)
		button.createButtonAlphaAnim(self,"QUIT",149 - display.screenOriginX,180,nil,0.7)
		button.createButtonAlphaAnim(self,"HELP",149 - display.screenOriginX,210,nil,0.7)
		button.createButtonAlphaAnim(self,"MAIN MENU",149 - display.screenOriginX,240,nil,0.7)
		if(image_char ~= nil) then
			image_char.x = 385 - display.screenOriginX
			image_char.y = 155
			image_char.xScale = -0.8
			image_char.yScale = 0.8
		end
	end
end

function castRay( event )
	return true
end

function resume( event )
	print("resume")
	storyboard.hideOverlay()
	return true
end

-- add event listener
scene:addEventListener("createScene", scene)

return scene